package com.xctech.yace.main;

import com.xctech.yace.pool.ProduceThreadPool;
import com.xctech.yace.service.KafkaSend;
import com.xctech.yace.util.TimeUtil;


public class YaceSend {
    public static void main(String[] args) {

        //1.1.并行事务发送
        asynSend(1);

        //2.串行发送（指令）
//        syncSend(3);

    }

    private static void syncSend(int n) {
        long s = System.nanoTime();
        KafkaSend send = new KafkaSend();
        String instruct ="{\"owner\":\"TRADE\",\"op\":0,\"optype\":\"INSERT\",\"actseq\":\"40.202993\",\"xid\":\"0x0003.01a.0000348a\",\"name\":\"TINSTRUCTION\",\"after_key\":{\"L_INDEX_DAILY_MODIFY\":\"1\",\"L_DAILY_INSTRUCTION_NO\":\"209675\"},\"jstime\":\"1632301486836086\",\"after\":{\"VC_MAC\":\"5EF3354B2442\",\"L_BEGIN_TIME\":\"100\",\"L_COMBITEMPLATE_ID\":\"0\",\"C_APPROVE_STATUS\":\"1\",\"L_INDEX_MODIFY_INSTRUCTION\":\"0\",\"C_ARBI_TYPE\":\"0\",\"L_END_TIME\":\"232000\",\"L_INVEST_TIME\":\"0\",\"L_INVEST_ADVISER\":\"0\",\"C_SOURCE\":\"1\",\"C_RISK_APPROVE_STATUS\":\"2\",\"C_TRADE_REASON\":\"1\",\"C_ENTRUST_RESTRICT\":\"1\",\"C_TARGET_TYPE\":\"1\",\"C_CANCEL_BRANCH_DEAL_STATUS\":\"0\",\"C_BUSIN_CLASS\":\"E\",\"VC_IP_ADDRESS\":\"192.168.0.17\",\"L_INVEST_DATE\":\"0\",\"L_END_DATE\":\"20210708\",\"C_OPERATOR_ASSESS\":\"1\",\"L_MODIFY_OPERATOR\":\"0\",\"L_ARBI_SETS\":\"0\",\"L_BUSIN_BEGIN_DATE\":\"20210708\",\"C_INSTRUCTION_TYPE\":\"1\",\"L_DEPT_ID\":\"0\",\"L_DAILY_INSTRUCTION_NO\":\"209675\",\"C_DEAL_EXECUTE_STATUS\":\"1\",\"UPDATED_TIME\":\"2021-07-08 14:27:44.000636\",\"EN_TARGET_BASE\":\"0\",\"L_APPROVE_DATE\":\"0\",\"L_BUSIN_END_DATE\":\"20210708\",\"L_HG_BATCH_NO\":\"0\",\"C_FAIR_TRADE\":\"1\",\"L_INSIDER_TRADING_NO\":\"0\",\"L_DISPENSE_DATE\":\"0\",\"C_ETF_AUTO\":\"0\",\"C_INSTRUCTION_LEVEL\":\"0\",\"L_FIRST_SETTLE_DATE\":\"20210622\",\"L_SCHEMA_ID\":\"0\",\"L_DIRECT_OPERATOR\":\"99991000\",\"D_DATETIME\":\"2021-07-08 14:27:44\",\"C_BRANCH_DEAL_STATUS\":\"0\",\"L_MODIFY_TIME\":\"0\",\"L_TRADE_RIVAL_NO\":\"101242\",\"L_DISPENSE_OPERATOR\":\"0\",\"C_PAPERY_APPROVE\":\"0\",\"L_APPROVE_TIME\":\"0\",\"L_ADVISE_ID\":\"0\",\"L_DISPENSE_TIME\":\"0\",\"L_APPROVE_BUSIN_DATE\":\"20210622\",\"L_ORG_ID\":\"0\",\"L_TOENTR_SETS\":\"0\",\"L_MODIFY_DATE\":\"0\",\"C_CANCEL_STATUS\":\"2\",\"L_INDEX_DAILY_MODIFY\":\"1\",\"L_BATCH_SERIAL_NO\":\"5379\",\"C_ENTRUST_EXECUTE_STATUS\":\"1\",\"C_LOCK_FLAG\":\"0\",\"L_HG_DAYS\":\"0\",\"L_GROUP_ID\":\"0\",\"VC_TRADE_FLAG\":\"0000\",\"L_CANCEL_OPERATOR\":\"0\",\"L_BASECOMBI_ID\":\"20085\",\"C_INSTRUCTION_STATUS\":\"1\",\"L_DIRECT_INSTEAD_OPERATOR\":\"99991000\",\"C_CANCEL_BRANCH_STATUS\":\"0\",\"EN_TARGET_VALUE\":\"1200\",\"C_QUOTE_SIDE\":\"0\",\"L_FUND_ID\":\"5000\",\"VC_VOLSERIAL_NO\":\"EJ94N195511104Q2H\",\"C_ETF_MANUAL\":\"0\",\"C_TRADE_AGENT_FLAG\":\"0\",\"L_SETTLE_SPEED\":\"1\",\"L_DEFAULT_OPERATOR\":\"0\",\"L_DIRECT_DATE\":\"20210708\",\"L_CANCEL_TIME\":\"0\",\"C_TARGET_BASE\":\"1\",\"L_CRMW_BATCH_SERIAL_NO\":\"0\",\"L_INDEX_LAST_MODIFY\":\"0\",\"C_DISPENSE_STATUS\":\"1\",\"L_APPLY_NO\":\"0\",\"L_DATE\":\"20210622\",\"D_HEART_BEAT\":\"2021-07-08 14:27:44\",\"L_CANCEL_DATE\":\"0\",\"L_INSTRUCTION_NO\":\"0\",\"L_SETTLE_LOCK_OPERATOR\":\"0\",\"C_BRANCH_STATUS\":\"0\",\"C_TREATYHG_FLAG\":\"0\",\"C_PRICE_CONTROL_TYPE\":\"1\",\"L_APPROVE_OPERATOR\":\"0\",\"C_SEARCH_SOURCE\":\"0\",\"C_SPECIAL_FLAG\":\"0\",\"L_DIRECT_TIME\":\"142744\",\"L_SECOND_SETTLE_DATE\":\"0\",\"C_FLOW_APPROVE_STATUS\":\"1\",\"C_EXEC_PHASE\":\"0\",\"C_STOCK_TARGET_TYPE\":\"2\",\"C_ADVISE_TYPE\":\"0\",\"L_LIMIT_OPERATOR\":\"0\",\"C_DEAL_EXECUTE_FLAG\":\"1\",\"L_BEGIN_DATE\":\"20210708\",\"VC_UNIQUE_INSTRUCTION_NO\":\"73234\",\"L_OPERATOR_NO\":\"0\"},\"scntime\":1625725664,\"rowid\":\"AAAINDAAFAAB7EKAAE\",\"scn\":\"693996326\"}";
        String instructStock = "{\"owner\":\"TRADE\",\"op\":0,\"optype\":\"INSERT\",\"actseq\":\"40.202994\",\"xid\":\"0x0003.01a.0000348a\",\"name\":\"TINSTRUCTIONSTOCK\",\"after_key\":{\"L_STOCK_SERIAL_NO\":\"0\",\"L_INDEX_DAILY_MODIFY\":\"1\",\"L_DAILY_INSTRUCTION_NO\":\"209675\"},\"jstime\":\"1632301486836760\",\"after\":{\"EN_FACT_PRICE\":\"100\",\"L_BEGIN_TIME\":\"20210708\",\"VC_INTER_CODE\":\"122002SS\",\"C_TRADE_TYPE\":\"100\",\"L_COMBI_ARBI_SETS\":\"0\",\"C_CASH_CONTROL_TYPE\":\"0\",\"EN_COMBI_TARGET_RATIO\":\"-0\",\"L_END_TIME\":\"1\",\"VC_RIVALTRADER_NAME\":\"\",\"C_MATCH_STATUS\":\"\",\"L_QUOTATION_OPERATOR\":\"0\",\"C_FIRST_SETTLE_TYPE\":\"\",\"C_BUSIN_CLASS\":\"\",\"L_END_DATE\":\"232000\",\"L_TODAY_DEAL_AMOUNT\":\"0\",\"L_DEPT_ID\":\"5000\",\"C_EXCEED_FLAG\":\"\",\"L_DAILY_INSTRUCTION_NO\":\"209675\",\"VC_REPORT_REFID\":\"0\",\"L_AMOUNT\":\"1200\",\"C_DEAL_EXECUTE_STATUS\":\"-0\",\"C_SECOND_SETTLE_TYPE\":\"\",\"L_RESTRICTED_NO\":\"0\",\"L_COMBI_TOENTR_SETS\":\"0\",\"C_ENTRUST_DIRECTION\":\"4\",\"EN_INSTR_TARGET_RATIO\":\"0\",\"VC_ENGAGED_NO\":\"\",\"VC_RIVAL_BANK_ACCOUNT\":\"\",\"L_STOCK_SERIAL_NO\":\"0\",\"C_FISP_FLAG\":\"0\",\"C_FASTREDEMPTION_FLAG\":\"\",\"L_TRADE_RIVAL_NO\":\"-4451515352E+20\",\"C_FUND_BONUS_TYPE\":\"\",\"C_OTHER_INVEST_TYPE\":\"\",\"C_ORIGINAL_DIRECTION\":\"\",\"L_ORG_ID\":\"0\",\"EN_CUM_AVG_PRICE\":\"0\",\"L_INDEX_DAILY_MODIFY\":\"1\",\"EN_DAILY_MAX\":\"0\",\"C_ENTRUST_EXECUTE_STATUS\":\"1\",\"EN_TOTAL_DEAL_BALANCE\":\"0\",\"D_DEAL_COMPLETE_DATE\":\"2021-06-29 5:58:18\",\"L_BASECOMBI_ID\":\"0\",\"C_INVEST_TYPE\":\"1\",\"C_INSTRUCTION_STATUS\":\"1\",\"EN_TARGET_VALUE\":\"0\",\"L_TOTAL_DEAL_AMOUNT\":\"0\",\"L_TOTAL_ENTRUST_AMOUNT\":\"0\",\"L_CASHGROUP_ID\":\"-E+28\",\"L_FUND_ID\":\"0\",\"EN_TODAY_DEAL_BALANCE\":\"0\",\"EN_EARNEST_BALANCE\":\"0\",\"L_SETTLE_SPEED\":\"20210622\",\"EN_BASIS\":\"101242\",\"L_ALGO_UNENTRUST_AMOUNT\":\"5000\",\"EN_TODAY_ENTRUST_BALANCE\":\"0\",\"L_TODAY_ENTRUST_AMOUNT\":\"0\",\"L_DATE\":\"20210622\",\"C_AMOUNT_BALANCE_FLAG\":\"\",\"C_BULKUNDERWEIGHT_FLAG\":\"\",\"EN_PRICE2\":\"0\",\"EN_PRICE1\":\"100\",\"VC_VOTE_SENATE_NO\":\"0\",\"EN_ESTIMATE_FEE\":\"-E+30\",\"C_PRICE_TYPE\":\"1\",\"L_DEAL_BONDLENDING_AMOUNT\":\"0\",\"EN_FEE\":\"0\",\"C_STOCK_CONTROL_TYPE\":\"\",\"EN_DAY_AVG_PRICE\":\"0\",\"EN_BALANCE\":\"120000\",\"L_BONDLENDING_AMOUNT\":\"0\",\"EN_ALGO_UNENTRUST_BALANCE\":\"0\",\"VC_ORIGIN_CONTRACT_NO\":\"\",\"VC_SOURCE_NO\":\"\",\"L_BEGIN_DATE\":\"100\",\"EN_PROFIT_RATIO\":\"0\"},\"scntime\":1625725664,\"rowid\":\"AAAK5IAAFAAAsNkAAE\",\"scn\":\"693996326\"}";

        for (int i =0;i<n;i++){
            instruct = TimeUtil.resetValue(instruct,"xid",String.valueOf(i+1));
            instructStock = TimeUtil.resetValue(instructStock,"xid",String.valueOf(i+1));
            send.sendMsgSyncNoAck("YACE",instruct);
            send.sendMsgSyncNoAck("YACE",instructStock);
        }

        long e = System.nanoTime();
        System.out.println(n+"笔"+"发送耗时："+(e-s)/1e6+"ms");
        ProduceThreadPool.stopPool(1000l*5);
    }

    private static void asynSend(int n) {
        long s = System.nanoTime();
        KafkaSend send = new KafkaSend();
        //263376911099000    cpu 纳秒
        //1632301486836086  jstime：微秒
        //1634039247012     系统毫秒数
        //1625725664        scntime: 秒
        String instruct ="{\"owner\":\"TRADE\",\"op\":0,\"optype\":\"INSERT\",\"actseq\":\"40.202993\",\"xid\":\"0x0003.01a.0000348a\",\"name\":\"TINSTRUCTION\",\"after_key\":{\"L_INDEX_DAILY_MODIFY\":\"1\",\"L_DAILY_INSTRUCTION_NO\":\"209675\"},\"jstime\":\"1632301486836086\",\"after\":{\"VC_MAC\":\"5EF3354B2442\",\"L_BEGIN_TIME\":\"100\",\"L_COMBITEMPLATE_ID\":\"0\",\"C_APPROVE_STATUS\":\"1\",\"L_INDEX_MODIFY_INSTRUCTION\":\"0\",\"C_ARBI_TYPE\":\"0\",\"L_END_TIME\":\"232000\",\"L_INVEST_TIME\":\"0\",\"L_INVEST_ADVISER\":\"0\",\"C_SOURCE\":\"1\",\"C_RISK_APPROVE_STATUS\":\"2\",\"C_TRADE_REASON\":\"1\",\"C_ENTRUST_RESTRICT\":\"1\",\"C_TARGET_TYPE\":\"1\",\"C_CANCEL_BRANCH_DEAL_STATUS\":\"0\",\"C_BUSIN_CLASS\":\"E\",\"VC_IP_ADDRESS\":\"192.168.0.17\",\"L_INVEST_DATE\":\"0\",\"L_END_DATE\":\"20210708\",\"C_OPERATOR_ASSESS\":\"1\",\"L_MODIFY_OPERATOR\":\"0\",\"L_ARBI_SETS\":\"0\",\"L_BUSIN_BEGIN_DATE\":\"20210708\",\"C_INSTRUCTION_TYPE\":\"1\",\"L_DEPT_ID\":\"0\",\"L_DAILY_INSTRUCTION_NO\":\"209675\",\"C_DEAL_EXECUTE_STATUS\":\"1\",\"UPDATED_TIME\":\"2021-07-08 14:27:44.000636\",\"EN_TARGET_BASE\":\"0\",\"L_APPROVE_DATE\":\"0\",\"L_BUSIN_END_DATE\":\"20210708\",\"L_HG_BATCH_NO\":\"0\",\"C_FAIR_TRADE\":\"1\",\"L_INSIDER_TRADING_NO\":\"0\",\"L_DISPENSE_DATE\":\"0\",\"C_ETF_AUTO\":\"0\",\"C_INSTRUCTION_LEVEL\":\"0\",\"L_FIRST_SETTLE_DATE\":\"20210622\",\"L_SCHEMA_ID\":\"0\",\"L_DIRECT_OPERATOR\":\"99991000\",\"D_DATETIME\":\"2021-07-08 14:27:44\",\"C_BRANCH_DEAL_STATUS\":\"0\",\"L_MODIFY_TIME\":\"0\",\"L_TRADE_RIVAL_NO\":\"101242\",\"L_DISPENSE_OPERATOR\":\"0\",\"C_PAPERY_APPROVE\":\"0\",\"L_APPROVE_TIME\":\"0\",\"L_ADVISE_ID\":\"0\",\"L_DISPENSE_TIME\":\"0\",\"L_APPROVE_BUSIN_DATE\":\"20210622\",\"L_ORG_ID\":\"0\",\"L_TOENTR_SETS\":\"0\",\"L_MODIFY_DATE\":\"0\",\"C_CANCEL_STATUS\":\"2\",\"L_INDEX_DAILY_MODIFY\":\"1\",\"L_BATCH_SERIAL_NO\":\"5379\",\"C_ENTRUST_EXECUTE_STATUS\":\"1\",\"C_LOCK_FLAG\":\"0\",\"L_HG_DAYS\":\"0\",\"L_GROUP_ID\":\"0\",\"VC_TRADE_FLAG\":\"0000\",\"L_CANCEL_OPERATOR\":\"0\",\"L_BASECOMBI_ID\":\"20085\",\"C_INSTRUCTION_STATUS\":\"1\",\"L_DIRECT_INSTEAD_OPERATOR\":\"99991000\",\"C_CANCEL_BRANCH_STATUS\":\"0\",\"EN_TARGET_VALUE\":\"1200\",\"C_QUOTE_SIDE\":\"0\",\"L_FUND_ID\":\"5000\",\"VC_VOLSERIAL_NO\":\"EJ94N195511104Q2H\",\"C_ETF_MANUAL\":\"0\",\"C_TRADE_AGENT_FLAG\":\"0\",\"L_SETTLE_SPEED\":\"1\",\"L_DEFAULT_OPERATOR\":\"0\",\"L_DIRECT_DATE\":\"20210708\",\"L_CANCEL_TIME\":\"0\",\"C_TARGET_BASE\":\"1\",\"L_CRMW_BATCH_SERIAL_NO\":\"0\",\"L_INDEX_LAST_MODIFY\":\"0\",\"C_DISPENSE_STATUS\":\"1\",\"L_APPLY_NO\":\"0\",\"L_DATE\":\"20210622\",\"D_HEART_BEAT\":\"2021-07-08 14:27:44\",\"L_CANCEL_DATE\":\"0\",\"L_INSTRUCTION_NO\":\"0\",\"L_SETTLE_LOCK_OPERATOR\":\"0\",\"C_BRANCH_STATUS\":\"0\",\"C_TREATYHG_FLAG\":\"0\",\"C_PRICE_CONTROL_TYPE\":\"1\",\"L_APPROVE_OPERATOR\":\"0\",\"C_SEARCH_SOURCE\":\"0\",\"C_SPECIAL_FLAG\":\"0\",\"L_DIRECT_TIME\":\"142744\",\"L_SECOND_SETTLE_DATE\":\"0\",\"C_FLOW_APPROVE_STATUS\":\"1\",\"C_EXEC_PHASE\":\"0\",\"C_STOCK_TARGET_TYPE\":\"2\",\"C_ADVISE_TYPE\":\"0\",\"L_LIMIT_OPERATOR\":\"0\",\"C_DEAL_EXECUTE_FLAG\":\"1\",\"L_BEGIN_DATE\":\"20210708\",\"VC_UNIQUE_INSTRUCTION_NO\":\"73234\",\"L_OPERATOR_NO\":\"0\"},\"scntime\":1625725664,\"rowid\":\"AAAINDAAFAAB7EKAAE\",\"scn\":\"693996326\"}";
        String instructStock = "{\"owner\":\"TRADE\",\"op\":0,\"optype\":\"INSERT\",\"actseq\":\"40.202994\",\"xid\":\"0x0003.01a.0000348a\",\"name\":\"TINSTRUCTIONSTOCK\",\"after_key\":{\"L_STOCK_SERIAL_NO\":\"0\",\"L_INDEX_DAILY_MODIFY\":\"1\",\"L_DAILY_INSTRUCTION_NO\":\"209675\"},\"jstime\":\"1632301486836760\",\"after\":{\"EN_FACT_PRICE\":\"100\",\"L_BEGIN_TIME\":\"20210708\",\"VC_INTER_CODE\":\"122002SS\",\"C_TRADE_TYPE\":\"100\",\"L_COMBI_ARBI_SETS\":\"0\",\"C_CASH_CONTROL_TYPE\":\"0\",\"EN_COMBI_TARGET_RATIO\":\"-0\",\"L_END_TIME\":\"1\",\"VC_RIVALTRADER_NAME\":\"\",\"C_MATCH_STATUS\":\"\",\"L_QUOTATION_OPERATOR\":\"0\",\"C_FIRST_SETTLE_TYPE\":\"\",\"C_BUSIN_CLASS\":\"\",\"L_END_DATE\":\"232000\",\"L_TODAY_DEAL_AMOUNT\":\"0\",\"L_DEPT_ID\":\"5000\",\"C_EXCEED_FLAG\":\"\",\"L_DAILY_INSTRUCTION_NO\":\"209675\",\"VC_REPORT_REFID\":\"0\",\"L_AMOUNT\":\"1200\",\"C_DEAL_EXECUTE_STATUS\":\"-0\",\"C_SECOND_SETTLE_TYPE\":\"\",\"L_RESTRICTED_NO\":\"0\",\"L_COMBI_TOENTR_SETS\":\"0\",\"C_ENTRUST_DIRECTION\":\"4\",\"EN_INSTR_TARGET_RATIO\":\"0\",\"VC_ENGAGED_NO\":\"\",\"VC_RIVAL_BANK_ACCOUNT\":\"\",\"L_STOCK_SERIAL_NO\":\"0\",\"C_FISP_FLAG\":\"0\",\"C_FASTREDEMPTION_FLAG\":\"\",\"L_TRADE_RIVAL_NO\":\"-4451515352E+20\",\"C_FUND_BONUS_TYPE\":\"\",\"C_OTHER_INVEST_TYPE\":\"\",\"C_ORIGINAL_DIRECTION\":\"\",\"L_ORG_ID\":\"0\",\"EN_CUM_AVG_PRICE\":\"0\",\"L_INDEX_DAILY_MODIFY\":\"1\",\"EN_DAILY_MAX\":\"0\",\"C_ENTRUST_EXECUTE_STATUS\":\"1\",\"EN_TOTAL_DEAL_BALANCE\":\"0\",\"D_DEAL_COMPLETE_DATE\":\"5300-00-00 00:127:-01\",\"L_BASECOMBI_ID\":\"0\",\"C_INVEST_TYPE\":\"1\",\"C_INSTRUCTION_STATUS\":\"1\",\"EN_TARGET_VALUE\":\"0\",\"L_TOTAL_DEAL_AMOUNT\":\"0\",\"L_TOTAL_ENTRUST_AMOUNT\":\"0\",\"L_CASHGROUP_ID\":\"-E+28\",\"L_FUND_ID\":\"0\",\"EN_TODAY_DEAL_BALANCE\":\"0\",\"EN_EARNEST_BALANCE\":\"0\",\"L_SETTLE_SPEED\":\"20210622\",\"EN_BASIS\":\"101242\",\"L_ALGO_UNENTRUST_AMOUNT\":\"5000\",\"EN_TODAY_ENTRUST_BALANCE\":\"0\",\"L_TODAY_ENTRUST_AMOUNT\":\"0\",\"L_DATE\":\"20210622\",\"C_AMOUNT_BALANCE_FLAG\":\"\",\"C_BULKUNDERWEIGHT_FLAG\":\"\",\"EN_PRICE2\":\"0\",\"EN_PRICE1\":\"100\",\"VC_VOTE_SENATE_NO\":\"0\",\"EN_ESTIMATE_FEE\":\"-E+30\",\"C_PRICE_TYPE\":\"1\",\"L_DEAL_BONDLENDING_AMOUNT\":\"0\",\"EN_FEE\":\"0\",\"C_STOCK_CONTROL_TYPE\":\"\",\"EN_DAY_AVG_PRICE\":\"0\",\"EN_BALANCE\":\"120000\",\"L_BONDLENDING_AMOUNT\":\"0\",\"EN_ALGO_UNENTRUST_BALANCE\":\"0\",\"VC_ORIGIN_CONTRACT_NO\":\"\",\"VC_SOURCE_NO\":\"\",\"L_BEGIN_DATE\":\"100\",\"EN_PROFIT_RATIO\":\"0\"},\"scntime\":1625725664,\"rowid\":\"AAAK5IAAFAAAsNkAAE\",\"scn\":\"693996326\"}";

        for (int i =0;i<n;i++){
            instruct = TimeUtil.resetValue(instruct,"xid",String.valueOf(i+1));
            instructStock = TimeUtil.resetValue(instructStock,"xid",String.valueOf(i+1));
            send.sendMsgAync("CDC",new String[]{instruct,instructStock});
        }
        long e = System.nanoTime();
        System.out.println(n+"笔"+"发送耗时："+(e-s)/1e6+"ms");
        ProduceThreadPool.stopPool(1000l*60);
    }

}
